package tuyou.kafka.consumer;

import java.util.Properties;

import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.common.serialization.StringDeserializer;

import tuyou.kafka.producer.ProducerTest;

/**
 * 消息消费者，获取所有topic
 * 
 * @author：涂有
 * @date 2017年6月1日 上午11:27:10
 */
public class ConsumerTest2 {

	public static void main(String[] args) {
		
		Properties properties = new Properties();
		properties.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getCanonicalName());// key反序列化方式
		properties.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getCanonicalName());// value反系列化方式
		properties.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, true);// 提交方式
		properties.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, ProducerTest.ip);// 指定broker地址，来找到group的coordinator
		properties.put(ConsumerConfig.GROUP_ID_CONFIG, "tuyou");// 指定用户组

		KafkaConsumer<String, String> consumer = new KafkaConsumer<>(properties);
		System.out.println(consumer.listTopics().keySet());
	}
}